package com.microservices.yucloud.business.rocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.ParameterizedTypeReference;

/**
 * @author zy
 * @date 2019/10/12 7:51 下午
 **/
@Configuration
@EnableBinding({ ChannelSink.class })
public class RocketConfig {
    @Bean
    public ConsumerCustomRunner customRunner() {
        return new ConsumerCustomRunner();
    }

    public static class ConsumerCustomRunner implements CommandLineRunner {

        @Autowired
        private ChannelSink mySink;

        @Override
        public void run(String... args) throws InterruptedException {
            while (true) {
                mySink.input5().poll(m -> {
                    String payload = (String) m.getPayload();
                    System.out.println("pull msg: " + payload);
                }, new ParameterizedTypeReference<String>() {
                });
                Thread.sleep(2_000);
            }
        }

    }
}
